package com.findu.activity;

import com.example.findu.R;
import com.example.findu.R.id;
import com.example.findu.R.layout;
import com.findu.control.Public_title_dynamic;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @ClassName: Home_More_Personal
 * @Description: TODO(个人信息)
 * @author hgf
 * @date 2015-11-4 上午11:54:28
 * 
 */
public class Home_More_Personal extends Activity implements OnClickListener {

	// 标题控制
	private Public_title_dynamic public_title;
	// 声明title布局
	private View include_view;

	// 声明意图
	private Intent intent;

	// 声明页面用到的元素
	private ImageView personal_User_ImageView_leftarrows;
	private ImageView personal_surname_leftarrows;
	private ImageView personal_Name_leftarrows;
	private ImageView personal_PhoneNumber_leftarrows;
	private ImageView personal_two_dimension_code_leftarrows;
	private ImageView personal_personal_Note_leftarrows;
	private ImageView personal_Region_leftarrows;

	private TextView personal_surname;
	private TextView personal_Name;
	private TextView personal_FindUID;
	private TextView personal_FindUName;
	private TextView personal_PhoneNumber;
	private TextView personal_two_dimension_code;
	private TextView personal_active_value;
	private TextView personal_Region;
	private TextView personal_personal_Note;
	private TextView personal_personal_EXIT;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_home__more__personal);

		// 初始化标题
		init_title();

		// 初始化各元素
		init_Other_element();
	}

	/**
	 * 初始化元素
	 */
	private void init_Other_element() {
		// TODO Auto-generated method stub

		// 用到的ImageView
		personal_User_ImageView_leftarrows = (ImageView) findViewById(R.id.personal_User_ImageView_leftarrows);
		personal_surname_leftarrows = (ImageView) findViewById(R.id.personal_surname_leftarrows);
		personal_Name_leftarrows = (ImageView) findViewById(R.id.personal_Name_leftarrows);
		personal_PhoneNumber_leftarrows = (ImageView) findViewById(R.id.personal_PhoneNumber_leftarrows);
		personal_two_dimension_code_leftarrows = (ImageView) findViewById(R.id.personal_two_dimension_code_leftarrows);
		personal_Region_leftarrows = (ImageView) findViewById(R.id.personal_Region_leftarrows);
		personal_personal_Note_leftarrows = (ImageView) findViewById(R.id.personal_personal_Note_leftarrows);

		

		// 用到的Textivew
		personal_personal_Note = (TextView) findViewById(R.id.personal_personal_Note);
		personal_surname = (TextView) findViewById(R.id.personal_surname);
		personal_Name = (TextView) findViewById(R.id.personal_Name);
		personal_FindUID = (TextView) findViewById(R.id.personal_FindUID);
		personal_FindUName = (TextView) findViewById(R.id.personal_FindUName);
		personal_PhoneNumber = (TextView) findViewById(R.id.personal_PhoneNumber);
		personal_two_dimension_code = (TextView) findViewById(R.id.personal_two_dimension_code);
		personal_active_value = (TextView) findViewById(R.id.personal_active_value);
		personal_Region = (TextView) findViewById(R.id.personal_Region);
		personal_personal_Note = (TextView) findViewById(R.id.personal_personal_Note);
		personal_personal_EXIT = (TextView) findViewById(R.id.personal_personal_EXIT);
		
		// 绑定监听事件
				personal_User_ImageView_leftarrows.setOnClickListener(this);
				personal_surname_leftarrows.setOnClickListener(this);
				personal_Name_leftarrows.setOnClickListener(this);
				personal_PhoneNumber_leftarrows.setOnClickListener(this);
				personal_two_dimension_code_leftarrows.setOnClickListener(this);
				personal_personal_Note_leftarrows.setOnClickListener(this);
				personal_Region_leftarrows.setOnClickListener(this);
				personal_personal_EXIT.setOnClickListener(this);
	}

	/**
	 * 初始化title
	 */
	private void init_title() {
		// 初始化title
		include_view = findViewById(R.id.home_More_personal_include);
		public_title = new Public_title_dynamic(include_view); // 新建工具类设置布局控件

		// title详细设置
		public_title.setTextLeft("更多");
		public_title.setTextView("个人信息");
		public_title.setRighttImageVisiable(false);
		public_title.setTextRight_Gone();

		// 设置标题事件
		ImageView leftImage = (ImageView) include_view
				.findViewById(R.id.public_title_dynamic__liftImage);
		leftImage.setOnClickListener(this);
	}

	/**
	 * 监听事件
	 */
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.public_title_dynamic__liftImage: // 标题左边监听事件
			finish();
			break;

		case R.id.personal_User_ImageView_leftarrows: // 头像跳转箭头

			intent = new Intent(Home_More_Personal.this,
					new Home_more_personal_Phot().getClass());
			startActivity(intent);
			break;

		// 修改姓跳转
		case R.id.personal_surname_leftarrows:
			intent = new Intent(Home_More_Personal.this,
					new Home_More_Personal_ChangeName().getClass());
			// 得到用户的姓
			String name = personal_surname.getText().toString().trim();
			intent.putExtra("userName", name);

			startActivityForResult(intent, 1);
			break;

		// 修改名跳转
		case R.id.personal_Name_leftarrows:
			intent = new Intent(Home_More_Personal.this,
					new Home_More_Personal_ChangeUserName().getClass());
			// 得到用户的姓
			String userName = personal_Name.getText().toString().trim();
			intent.putExtra("Name", userName);

			startActivityForResult(intent, 2);
			break;

		// 修改电话跳转
		case R.id.personal_PhoneNumber_leftarrows:
			intent = new Intent(Home_More_Personal.this,
					new Home_More_Person_changePhone().getClass());
			// 得到用户的姓
			String Phone = personal_PhoneNumber.getText().toString().trim();
			intent.putExtra("Phone", Phone);

			startActivityForResult(intent, 3);
			break;

		// 生成二维码跳转
		case R.id.personal_two_dimension_code_leftarrows: // 二维码跳转
			intent = new Intent(Home_More_Personal.this,
					new Home_More_Person_twoDimension_code().getClass());

			startActivity(intent);
			break;
		case R.id.personal_personal_Note_leftarrows: // 选择地址

			break;
		case R.id.personal_Region_leftarrows: // 个人描述跳转
			intent = new Intent(Home_More_Personal.this,
					More_personal_SelectCitiesDialogActivity.class);

			startActivityForResult(intent, 4);
			break;
		case R.id.personal_personal_EXIT:	//用户退出按钮
			
			finish();
			break;
		default:
			break;
		}
	}

	/**
	 * 接收上面界面传递过来的值
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 1:
			if (resultCode == RESULT_OK) {
				if (requestCode == 1) {
					String user_Name = data.getStringExtra("userName");
					personal_surname.setText(user_Name);
					Toast.makeText(Home_More_Personal.this, "修改成功！",
							Toast.LENGTH_SHORT).show();

				}
			}
			break;
		case 2:
			if (resultCode == RESULT_OK) {
				if (requestCode == 2) {
					String user_Name = data.getStringExtra("Name");
					personal_Name.setText(user_Name);
					Toast.makeText(Home_More_Personal.this, "修改成功！",
							Toast.LENGTH_SHORT).show();

				}
			}
			break;
		case 3:
			if (resultCode == RESULT_OK) {
				if (requestCode == 3) {
					String user_Name = data.getStringExtra("Phone");
					personal_PhoneNumber.setText(user_Name);
					Toast.makeText(Home_More_Personal.this, "修改成功！",
							Toast.LENGTH_SHORT).show();

				}
			}
			break;
		case 4:
			if (resultCode == RESULT_OK) {
				if (requestCode == 4) {
					personal_Region.setText(data.getStringExtra("address"));
					Toast.makeText(Home_More_Personal.this, "成功修改地址！",
							Toast.LENGTH_SHORT).show();
				}
			}

			break;

		}

	}
}
